package topuc.com.mvp.bean;

import android.graphics.Canvas;
import android.graphics.Paint;
import android.icu.text.LocaleDisplayNames;
import android.util.Log;

import topuc.com.mvp.R;

/**
 * WheelView每个Item所包含的属性
 * Created by apls on 2018/12/13.
 */
public class ItemObject {

    /**
     * item的x坐标
     */
    private float x;

    /**
     * item的y坐标
     */
    private float y;

    /**
     * item文本的内容
     */
    private String text;

    private Paint mPaint;
    private int moveY=0;

    /**
     *
     */
    public ItemObject(){

        mPaint=new Paint();
        mPaint.setAntiAlias(true);
        mPaint.setTextSize(40);
    }

    /**
     * 绘制条目
     */
    public void drawSelf(Canvas canvas,int viewWidth,int viewHeight){

        float baseX=viewWidth/2-mPaint.measureText(text)/2;

        Paint.FontMetricsInt fmi=new Paint.FontMetricsInt();

        int moveDistance=(fmi.bottom-fmi.top)/2-fmi.bottom;
        float baseY=viewHeight/2+moveDistance;
        canvas.drawText(text,baseX,moveY+y+baseY,mPaint);
    }

    /**
     * 判断条目是否在正中间
     */
    public boolean isSelected(int viewHeight,int unitHeight){

        if(y+moveY>=viewHeight/2-unitHeight/2&&(y+moveY)<=viewHeight/2+unitHeight/2){

            return true;
        }

        return false;
    }

    /**
     * 获取移动到正中间位置所需移动的距离
     * @return
     */
    public int moveToSelected(int viewHeight,int unitHeight,float move){

        int distance= (int) ((viewHeight/2-unitHeight/2)-(y+move));
        Log.d("WheelView","viewHeight:"+viewHeight+",unitHeight:"+unitHeight+",move:"+move+",distance:"+distance+",y:"+y);

        return distance;
    }

    public void newY(int move){

        this.moveY=0;
        this.y=y+move;
    }

    public float getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public float getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    public void move(int moveY) {
     this.moveY=moveY;
    }
}